package main

import (
	"fmt"
	"math/rand"
	"strconv"
	"time"
)

var (
	initPokerOrder, pokerOrder []string
)

func main() {
	// 生成初始化顺序的扑克牌
	pokerColors := [...]string{"♠", "♥", "♣", "♦"}
	for _, color := range pokerColors {
		initPokerOrder = AddCards(color)
	}
	initPokerOrder = append(initPokerOrder, "大王", "小王")
	fmt.Println("初始顺序：")
	fmt.Println(initPokerOrder)
	// 随机从初始化的牌中抽取一张牌放到新切片中
	for len(initPokerOrder) > 0 {
		rand.Seed(time.Now().Unix())
		randIndex := rand.Intn(len(initPokerOrder))
		pokerOrder = append(pokerOrder, initPokerOrder[randIndex])
		initPokerOrder = removeElementByIndex(initPokerOrder, randIndex)
	}
	fmt.Println("打乱顺序：")
	fmt.Println(pokerOrder)
}

func AddCards(color string) (slice []string) {
	for i := 1; i <= 13; i++ {
		switch i {
		case 1:
			initPokerOrder = append(initPokerOrder, color+"A")
		case 11:
			initPokerOrder = append(initPokerOrder, color+"J")
		case 12:
			initPokerOrder = append(initPokerOrder, color+"Q")
		case 13:
			initPokerOrder = append(initPokerOrder, color+"K")
		default:
			initPokerOrder = append(initPokerOrder, color+strconv.Itoa(i))

		}
	}
	return initPokerOrder
}

func removeElementByIndex(s []string, index int) []string {
	return append(s[:index], s[index+1:]...)
}
